﻿using B.S.Base.Write.API.Application.Command;
using MediatR;
using WEBAPI.Damoin;
using WEBAPI.ErroeCode;
using WEBAPI.Indaseture.Infasetures;

namespace B.S.Base.Write.API.CommandHandLer
{
    public class DeltetRoleCommandHandLer : IRequestHandler<DeleteRoleCommand, APIResult<int>>
    {
       private readonly IBaseRepostiy<RoleModel> _roleModel;

        public DeltetRoleCommandHandLer(IBaseRepostiy<RoleModel> _roleModel)
        {
            this._roleModel = _roleModel;
        }

        public async Task<APIResult<int>> Handle(DeleteRoleCommand request, CancellationToken cancellationToken)
        {
            var list = _roleModel.GetAll().FirstOrDefault(x => !x.IsDeleted && x.RoleId == request.RoleId);
            list.IsDeleted = true;
            await _roleModel.Update(list);
            return new APIResult<int>()
            {
                Code = ResultCode.Ok,
                Message = "删除成功",
                Data = 1,
            };
        }
    }
}
